let main = document.querySelector("#main")


function getUrlParams() {
    let url = window.location.search;
    let regExp = /.*\?([^\?]+)/
    let query = {};//最终处理好的参数
    let search = regExp.exec(url);
    //productid=23&NAME=123"
    // console.log(search);
    search = search[1];
    //有没有多个query参数,有的话肯定以&进行连接
    let searchArr = [];
    if (search.indexOf("&")) {
        searchArr = search.split("&")
    } else {
        search = search.split()
    }

    searchArr.forEach(item => {
        let queryArr = item.split("=");
        query[queryArr[0]] = queryArr[1]
    })

    return query
}

let query = getUrlParams();
let searchtxt = decodeURI(query.use)
console.log(searchtxt)
fetch(`http://chst.vip:1234/api/getbrandproductlist?brandtitleid=${query.brandtitleid}&pagesize=10`)
    .then(body => body.json())
    .then(res => {
        let html = ""
        let oo = document.querySelector(".oo")
        oo.innerHTML = searchtxt
        res.result.forEach(item => {
            html += ` <li class="ll" productid=${item.productId} brandname=${item.brandName} >
        ${item.productImg}
        <div class="dv">
            <p class="p1"> ${item.productName}</p>
            <p class="p2"> ${item.productPrice}</p>
            <p class="p3">
            <span class="s1">${item.productQuote}</span >
            <span class="s2"><i class="iconfont icon-biaoqing" style="color:red"></i>${item.productCom}</span></p>
        </div>
    </li>`
        })
        main.innerHTML = html
        let ll = document.querySelectorAll(".ll")
        ll.forEach(li => {
            li.onclick = function () {
                let ctid = this.getAttribute("productid")
                let brand = this.getAttribute("brandname")
                location.href = `./../pages/productlist.html?brandtitleid=${query.brandtitleid}&productId=${ctid}&text1=${brand}`
            }
        })
        let btn = document.querySelector("#Top")
        window.onscroll = function () {
            btn.onclick = function () {
                document.documentElement.scrollTop = 0
            }

        }
    })